package com.qianchang.microfinance.view.hsmywallet;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;

import com.dm.library.adapter.BaseViewPagerAdapter;
import com.dm.library.adapter.FragmentPageInfo;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.global.ConstantAppInfo;
import com.qianchang.microfinance.view.base.BaseActivity;

import java.lang.reflect.Field;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 *  鸿胜科技新增我的钱包充值中心 2018.1.16
 */

public class HSRecharCentreActivity extends BaseActivity {

    private static final String TAG        = "HSMyWallterActivity";

    public static final String URL_TYPE = "url_type";
    @BindView(R.id.tab_wallter_type)
    TabLayout tabLoanType;
    @BindView(R.id.viewpager)
    ViewPager viewPager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge_centre_layout);
        ButterKnife.bind(this);
        initData();
    }


    @Override
    protected void initData() {
        super.initData();
        setTitleName(getString(R.string.rechar_centre));

        initViewPager();

    }

    private void initViewPager() {
        BaseViewPagerAdapter adapter = new BaseViewPagerAdapter(this, getSupportFragmentManager(), getPagerInfo());
        viewPager.setAdapter(adapter);
        tabLoanType.setupWithViewPager(viewPager);
    }

    private FragmentPageInfo[] getPagerInfo() {

//        tabLoanType.setVisibility(View.VISIBLE);
        tabLoanType.setVisibility(View.GONE);
        tabLoanType.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLoanType,30,30);
            }
        });
        return new FragmentPageInfo[]{
                new FragmentPageInfo(getString(R.string.rechar_Balance), HSRecharBalanceFragment.class, setBundleData(0, "cash")),
//                new FragmentPageInfo(getString(R.string.rechar_gold), HSRecharGoldFragment.class, setBundleData(4, "campus")),
        };
    }

    public Bundle setBundleData(int productType, String urlType) {
        Bundle bundle = new Bundle();
        bundle.putInt(ConstantAppInfo.PROJECT_TYPE, productType);
        bundle.putString(URL_TYPE, urlType);
        return bundle;
    }

    public void setIndicator (TabLayout tabs,int leftDip,int rightDip) {
        Class<?> tabLayout = tabs.getClass();
        Field tabStrip = null;
        try {
            tabStrip = tabLayout.getDeclaredField("mTabStrip");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        tabStrip.setAccessible(true);
        LinearLayout llTab = null;
        try {
            llTab = (LinearLayout) tabStrip.get(tabs);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, leftDip, Resources.getSystem().getDisplayMetrics());
        int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rightDip, Resources.getSystem().getDisplayMetrics());

        for (int i = 0; i < llTab.getChildCount(); i++) {
            View child = llTab.getChildAt(i);
            child.setPadding(0, 0, 0, 0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
            params.leftMargin = left;
            params.rightMargin = right;
            child.setLayoutParams(params);
            child.invalidate();
        }
    }


    @OnClick({R.id.tv_right})
    public void onViewClicked(View view) {
        if (view.getId() == R.id.tv_right) {

            return;
        }
    }




}